﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MercuryFE
{
    public partial class SmartRetrieve : Form
    {
        private string _fileType = "";
        public string DownloadedFile = "";
        private string _zippattern = "";
        

        public SmartRetrieve(string fileType)
        {
            InitializeComponent();
            _fileType = fileType;
            this.Load += new EventHandler(SmartRetrieve_Load);
        }

        void SmartRetrieve_Load(object sender, EventArgs e)
        {
            string zippattern = "";
            string linkdisplay = "";
            Dictionary<string, string> fileLinks = LauncherLib.getFileLinks(_fileType, ref zippattern, ref linkdisplay);
            _zippattern = zippattern;
            List<KeyValuePair<string,string>> links = new List<KeyValuePair<string,string>>();
            foreach (KeyValuePair<string, string> item in fileLinks)
            {
                links.Add(item);
            }

            lblLinkDisplay.Text = linkdisplay;
            cmbFileToDownload.DataSource = links;
            cmbFileToDownload.DisplayMember = "Key";
            cmbFileToDownload.ValueMember = "Value";
        }

        private void btnSmartRetrieveFolderSelection_Click(object sender, EventArgs e)
        {
            tbSmartRetrieveDestinationFolder.Text = LauncherLib.getFolderSelection();
        }

        private void btnSmartRetrieveDownload_Click(object sender, EventArgs e)
        {
            string fileURL = ((KeyValuePair<string,string>)cmbFileToDownload.SelectedItem).Value.ToString();
            string destFolder = tbSmartRetrieveDestinationFolder.Text;
            DownloadedFile =  LauncherLib.downloadFile(fileURL, destFolder, _zippattern);
            this.Close();
        }
    }


}
